<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.returnId ? '查看' : '查看'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
    <el-row :gutter="28">
      <el-col :span="12">
        <el-form-item label="订单编号:" prop="orderNo">
          <span>{{dataForm.orderNo}}</span>
        <!-- <el-input v-model="dataForm.orderNo" placeholder="订单编号"></el-input> -->
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="用户是否收到货:" prop="userGetGoods">
          <span>{{userGetGoods1[dataForm.userGetGoods]}}</span>
        <!-- <el-input v-model="dataForm.userGetGoods" placeholder="用户是否收到货"></el-input> -->
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="28">
      <el-col :span="12">
        <el-form-item label="退款订单来源:" prop="returnOrderSrc">
          <span>{{returnOrderSrc1[dataForm.returnOrderSrc]}}</span>
        <!-- <el-input v-model="dataForm.returnOrderSrc" placeholder="退款订单来源"></el-input> -->
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="退货状态:" prop="returnStatus">
          <span>{{returnStatus1[dataForm.returnStatus]}}</span>
        <!-- <el-input v-model="dataForm.returnStatus" placeholder="退货状态"></el-input> -->
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="18">
      <el-col :span="12">
        <el-form-item label="申请退还金额:" prop="applyReturnMoney">
          <span>{{dataForm.applyReturnMoney}}</span>
        <!-- <el-input v-model="dataForm.applyReturnMoney" placeholder="申请退还金额"></el-input> -->
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="申请退货备注:" prop="applyReturnRemark">
          <span>{{dataForm.applyReturnRemark}}</span>
        <!-- <el-input v-model="dataForm.applyReturnRemark" placeholder="申请退货备注"></el-input> -->
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="18">
      <el-col :span="12">
        <el-form-item label="申请退货时间:" prop="applyReturnTime">
          <span>{{dataForm.applyReturnTime}}</span>
        <!-- <el-input v-model="dataForm.applyReturnTime" placeholder="申请退货时间"></el-input> -->
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="商家手机号:" prop="storeMobile">
          <span>{{dataForm.storeMobile}}</span>
          <!-- <el-input v-model="dataForm.storeMobile" placeholder="商家手机号"></el-input> -->
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item label="退货图片:" prop="img">
      <el-upload
        action=""
        list-type="picture-card"
        :file-list="dataForm.img"
        :on-preview="handlePreview"
        :on-success="handleSuccess"
        :on-remove="handleRemove"
        :on-exceed="onExceed">
        <i class="el-icon-plus"></i>
      </el-upload>
      <!-- <el-input v-model="dataForm.img" placeholder="退货图片"></el-input> -->
    </el-form-item>
    <el-row :gutter="18">
      <el-col :span="12">
        <el-form-item label="实际店家审核时间:" prop="returnAuditTime">
          <span>{{dataForm.returnAuditTime}}</span>
        <!-- <el-input v-model="dataForm.returnAuditTime" placeholder="实际店家审核时间"></el-input> -->
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="店铺审核审核的备注:" prop="userAuditRemark">
          <span>{{dataForm.userAuditRemark}}</span>
        <!-- <el-input v-model="dataForm.userAuditRemark" placeholder="店铺审核审核的备注"></el-input> -->
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="28">
      <el-col :span="12">
        <el-form-item label="第三方流水号:" prop="tradeNo">
          <span>{{dataForm.tradeNo}}</span>
        <!-- <el-input v-model="dataForm.tradeNo" placeholder="第三方流水号"></el-input> -->
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="购买人账号:" prop="userName">
          <span>{{dataForm.userName}}</span>
        <!-- <el-input v-model="dataForm.userName" placeholder="购买人账号"></el-input> -->
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="28">
      <el-col :span="12">
        <el-form-item label="购买人名称:" prop="trueName">
          <span>{{dataForm.trueName}}</span>
        <!-- <el-input v-model="dataForm.trueName" placeholder="购买人名称"></el-input> -->
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="购买人手机号:" prop="mobile">
          <span>{{dataForm.mobile}}</span>
        <!-- <el-input v-model="dataForm.mobile" placeholder="购买人手机号"></el-input> -->
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="28">
      <el-col :span="12">
        <el-form-item label="商家账号:" prop="storeUserName">
          <span>{{dataForm.storeUserName}}</span>
        <!-- <el-input v-model="dataForm.storeUserName" placeholder="商家账号"></el-input> -->
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="商家名称:" prop="storeTrueName">
          <span>{{dataForm.storeTrueName}}</span>
        <!-- <el-input v-model="dataForm.storeTrueName" placeholder="商家名称"></el-input> -->
        </el-form-item>
      </el-col>
    </el-row>
    </el-form>
    <!-- <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span> -->
  </el-dialog>
</template>

<script>
  import {userGetGoodsType, returnOrderSrcType, returnStatusType} from '../../../utils/storereturn'
  export default {
    data () {
      return {
        visible: false,
        dialogImageUrl: '',
        dialogVisible: false,
        userGetGoods1: userGetGoodsType,
        returnOrderSrc1: returnOrderSrcType,
        returnStatus1: returnStatusType,
        dataForm: {
          returnId: 0,
          orderNo: '',
          userGetGoods: '',
          img: [],
          returnStatus: '',
          applyReturnMoney: '',
          applyReturnRemark: '',
          applyReturnTime: '',
          returnOrderSrc: '',
          returnAuditTime: '',
          userAuditRemark: '',
          tradeNo: '',
          userName: '',
          trueName: '',
          mobile: '',
          storeUserName: '',
          storeTrueName: '',
          storeMobile: ''
        },
        dataRule: {
          classname: [
            { required: true, message: '分类名称不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.returnId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.returnId) {
            this.$http({
              url: this.$http.adornUrl(`/business/getStoreReturnById/${this.dataForm.returnId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.classname = data.data.returnId
                this.dataForm.orderNo = data.data.orderNo
                this.dataForm.userGetGoods = data.data.userGetGoods
                for (var i = 0; i < data.data.img.length; i++) {
                  this.dataForm.img.push({name: 'tu', url: 'http://image.yilianbaihui.cn/consumer/' + data.data.img[i]})
                }
                // this.dataForm.img = data.data.img
                this.dataForm.returnStatus = data.data.returnStatus
                this.dataForm.applyReturnMoney = data.data.applyReturnMoney
                this.dataForm.applyReturnRemark = data.data.applyReturnRemark
                this.dataForm.applyReturnTime = data.data.applyReturnTime
                this.dataForm.returnOrderSrc = data.data.returnOrderSrc
                this.dataForm.returnAuditTime = data.data.returnAuditTime
                this.dataForm.userAuditRemark = data.data.userAuditRemark
                this.dataForm.tradeNo = data.data.tradeNo
                this.dataForm.userName = data.data.userName
                this.dataForm.trueName = data.data.trueName
                this.dataForm.mobile = data.data.mobile
                this.dataForm.storeUserName = data.data.storeUserName
                this.dataForm.storeTrueName = data.data.storeTrueName
                this.dataForm.storeMobile = data.data.storeMobile
              }
            })
          }
        })
      },
      // 图片预览
      handlePreview (file) {
        this.dialogImageUrl = file.url
        this.dialogVisible = true
      },
      // 文件上传成功的钩子函数
      handleSuccess (res, file, fileList) {
        this.$message({
          type: 'info',
          message: '图片上传成功',
          duration: 6000
        })
        if (res.code === 0) {
          this.dataForm.img.push({name: 'tupian', url: 'http://image.yilianbaihui.cn/consumer/' + res.data})
        //   this.dataForm.goodsimg = res.data
        }
      },
      // 删除文件之前的钩子函数
      handleRemove (file, fileList) {
        for (var i = 0; i < this.dataForm.img.length; i++) {
          var picc = this.dataForm.img[i]
          if (picc.url === file.url) {
            this.dataForm.img.splice(i, 1)
            this.dataForm.img = ''
          }
        }
        this.$message({
          type: 'info',
          message: '已删除原有图片',
          duration: 6000
        })
      },
      // 上传的文件个数超出设定时触发的函数
      onExceed (files, fileList) {
        this.$message({
          type: 'info',
          message: '最多只能上传1个图片',
          duration: 6000
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/business/class/${!this.dataForm.id ? 'addClass' : 'modifyByIds'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'classname': this.dataForm.classname
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
